﻿<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Xml.Linq;
using System.Web.Caching;

public class Handler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "application/xml";
        context.Response.Charset = "utf-8";
        string guid = context.Request.Form["guid"];
        Maticsoft.Common.DownloadingFileInfo info = context.Cache[guid] as Maticsoft.Common.DownloadingFileInfo;
        XDocument doc = new XDocument();
        XElement root = new XElement("root");
        if (info != null)
        {
            XElement fileName = new XElement("fileName", info.FileName);
            XElement fileFinished = new XElement("fileFinished", info.FileFinished);
            XElement fileSize = new XElement("fileSize", info.FileSize);
            XElement costTime = new XElement("costTime", info.CostTime);
            XElement fileState = new XElement("fileState", info.FileState);
            XElement speed = new XElement("speed",info.Speed);
            XElement percent = new XElement("percent",info.Percent);
            XElement abort = new XElement("abort",false);
            root.Add(fileName);
            root.Add(fileFinished);
            root.Add(fileSize);
            root.Add(costTime);
            root.Add(fileState);
            root.Add(speed);
            root.Add(percent);
            if (info.Abort)
            {
                abort.Value = info.Abort.ToString();
                context.Cache.Remove(guid);
            }
            if (info.FileState == "finished")
            {
                context.Cache.Remove(guid);
            }
            
            
        }
        else
        {
            XElement none = new XElement("none","no file");
            root.Add(none);
        }
        doc.Add(root);
        context.Response.Flush();
        context.Response.Write(doc.ToString());
        
        context.Response.End();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}